<?php
ob_start();
session_start();
include("utils.php");
unset($_SESSION['uploaded_file_name']);
main_content("mainBuySpace();");
function mainBuySpace()
{

	if($_SESSION['langId']!="")
	{
		$langId=$_SESSION['langId'];
	}
	else
	{
		$langId="1";
	}
	$sql="select s.*,adm.*,addet.adspaceType FROM ".SITEMASTER." as s,".ADSPSCEMASTER." as adm,".ADSPACEDETAILS." as addet where s.langId='".$langId."' and s.adsiteId=adm.adsiteId and addet.adspaceId=adm.adspaceId";
	$query=mysql_query($sql);
	
	if(isset($_SESSION[siteuserId]) && $_SESSION[siteuserId]!='')
		$callFunction = "addtoFav();";
	else
		$callFunction = "location.href='index.php'";
		
	$sqlNetworkAds = "select * from ".NETWORKMASTER.",".NETWORKDETAILS." where ".NETWORKMASTER.".status='Y' AND ".NETWORKMASTER.".networkId=".NETWORKDETAILS.".networkId";
	$execNetworkAds = mysql_query($sqlNetworkAds);
	$network_num=mysql_num_rows($execNetworkAds);
	$fetMaxId = mysql_fetch_array(mysql_query("select MAX(networkId),MIN(networkId) from ".NETWORKMASTER." where status='Y'"));
?>
<script type="text/javascript" language="javascript">
  <!--
      var theme_path = 'images'; //set current theme path
  -->
</script>
<script type="text/javascript" language="javascript" src="JavaScripts/js.html"></script>
<script language="javascript" src="JavaScripts/calendar.js"></script>
<script src="JavaScripts/jsBuyNetworkAds.js"></script>

<input type="hidden" name="hidAdSpaceId" id="hidAdSpaceId" value="">
<table  border="0" width="90%"  cellspacing="0" cellpadding="0">
	<tr>
		<td valign="top" align="center">
			<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr>
					<td width="244px" valign="top"><?php include("left_pannel.php"); ?></td>
					<td width="14" valign="top">&nbsp;</td>
					<td valign="top">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td>
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
										  <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
										  <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
										  <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
										</tr>
									 </table>
								</td>
							</tr>
							<tr>
								<td class="PinkTwosideBorder BoxContent" valign="top" align="center">
									<table width="95%" cellspacing="0" cellpadding="0" border="0" align="center">
										<TR>
										  <TD align="center" class="sky font-18"><?php echo BUYNETWORKADS;?></TD>
										</TR>
										<TR>
										  <TD align="center"><?php echo BUYADSMSG;?></TD>
										</TR>
										<TR>
											<TD align="right">
												<table width="100%" border="0">
													<TR>
														<TD align="left"><?php if($network_num>0){?><A href="javascript:void(0);" class="listLink" onClick="showAll(<?php echo $fetMaxId[1]; ?>,<?php echo $fetMaxId[0]; ?>)"><?php echo EXPANDALL;?></A> / <A href="javascript:void(0);" class="listLink" onClick="closeAll(<?php echo $fetMaxId[1]; ?>,<?php echo $fetMaxId[0]; ?>)"><?php echo CLOSEALL;?></A><?php } else echo "No Network Ads Found"?></TD>
														<TD align="right"><input type="button" onClick="location.href='buildCustomNetwork.php'" value="<?php echo BUILDCUSTOMNETWORK;?>"></TD>
													</TR>
												</table>
											</TD>
										</TR>
										<TR>
											<TD align="center">&nbsp;</TD>
										</TR>
										<tr>
										<td valign="top" align="left">
											<table width="100%" border="0">
													<?php 
													while($fetNetworkAds = mysql_fetch_array($execNetworkAds))
													{
														$getClicksPurchase = mysql_query("select * from network_clicks_purchase where networkId='".$fetNetworkAds[networkId]."'");
														$countClicksPurchase = mysql_num_rows($getClicksPurchase);
														$readonly = '';
														if($countClicksPurchase>0)
															$readonly = 'readonly';
													?>
													<form method="post" action="advertiser_direct_network.php" name="a<?=$fetNetworkAds[networkId]?>">
														<tr>
															<TD align="left"><input type="hidden" name="networkType" id="networkType" value="<?php echo $fetNetworkAds[networkType]; ?>">
																<table width="100%" cellspacing="0" cellpadding="0" border="0">
																	<tr>
																		<TD align="left"><a href="#" class="listLink" onClick="expandCollapse(<?php echo $fetNetworkAds[networkId];?>);" id="plus<?php echo $fetNetworkAds[networkId];?>" name="network_id<?=$fetNetworkAds[networkId]?>">+</a> <a class="listLink" href="#" style="display:none;" id="minus<?php echo $fetNetworkAds[networkId];?>" onClick="expandCollapse(<?php echo $fetNetworkAds[networkId];?>);">-</a>&nbsp; <A class="listLink" href="#" onClick="expandCollapse(<?php echo $fetNetworkAds[networkId];?>);"><?php echo strtoupper($fetNetworkAds[networkType]); ?>&nbsp;&nbsp;-&nbsp;&nbsp;<?php echo ucfirst($fetNetworkAds[networkName]); ?>&nbsp;( $<?php echo $fetNetworkAds[networkMinPrice].' '.$fetNetworkAds[networkBidType]; ?>)</A> </TD>
																		<!-- Start Values for post -->
																		<td style="display:none;"><inPUT type="text" name="network_type" value="<?=$fetNetworkAds[networkType]?>"></td>
																		<td style="display:none;"><inPUT type="hidden" name="network_id" value="<?=$fetNetworkAds[networkId]?>"></td>
																		<td style="display:none;"><inPUT type="hidden" name="post_checking" value="www"></td>
																		<!-- End Values for post -->
																	</TR>
																	<tr>
																		<TD align="left" colspan="4" id="tdDetails<?php echo $fetNetworkAds[networkId];?>" style="display:none;padding-left:3px;">
																			<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
																				<tr>
																					<td align="left" valign="top" class="dayboxboder">
																						<table width="100%" border="0" cellspacing="0" cellpadding="0">
																							<tr>
																								<td align="left" valign="top" class="boxbg">
																									<table width="100%" border="0" cellspacing="0" cellpadding="0">
																										<tr>
																											<td width="142" align="center" valign="top" bgcolor="#FFFFFF" class="rightboder"><img src="<?php echo $GLOBALS[SiteUrl]?>images/noimage.jpg" alt=" " width="96" height="96" /></td>
																											<td width="281" align="left" valign="top" class="rightboder">
																												<table width="100%" border="0" cellspacing="0" cellpadding="0">
																													<tr>
																														<td height="20" align="left" valign="top">&nbsp;</td>
																													</tr>
																													<tr>
																														<td align="left" valign="top">
																															<table width="100%" border="0" cellspacing="0" cellpadding="0">
																																<tr>
																																  <td width="122" align="left" valign="middle" class="boxtxt"><strong>Clicks To Purchase</strong>&nbsp;
																																	<input type="text" id="txtTotalCost<?php echo $fetNetworkAds[networkId];?>" name="txtTotalCost" onKeyUp="AcceptDigits(document.getElementById('txtTotalCost<?php echo $fetNetworkAds[networkId];?>'));showPriceVal(this.value,<?php echo $fetNetworkAds[networkMinPrice];?>,<?php echo $fetNetworkAds[networkId];?>);" <?php echo $readonly;?>></td>
																																  <td width="10" align="left" valign="top">&nbsp;</td>
																																</tr>
																															</table>
																														</td>
																													</tr>
																													<tr>
																														<td align="center" valign="top"><strong>Auto-Subtotal:</strong> &nbsp;<span id="spanTotCost<?php echo $fetNetworkAds[networkId];?>"></span></td>
																													</tr>
																													<tr>
																														<td height="10" align="left" valign="top"></td>
																													</tr>
																													<tr>
																														<td align="left" valign="top">
																															<table width="100%" border="0" cellspacing="0" cellpadding="0">
																																<tr>
																																  <td align="left" valign="top">&nbsp;</td>
																																  <td align="right" valign="top"><input type="submit" name="btnAddToCart_<?=$fetNetworkAds[networkId]?>" value="Add To Cart"></td>
																																  <td width="10" align="left" valign="top">&nbsp;</td>
																																</tr>
																															</table>
																														</td>
																													</tr>
																													<tr>
																														<td align="left" valign="top">&nbsp;</td>
																													</tr>
																												</table>
																											</td>
																											<td align="left" valign="top">
																												<table width="100%" border="0" cellspacing="0" cellpadding="0">
																													<tr>
																														<td align="left" valign="top" class="boxboder">
																															<table width="100%" border="0" cellspacing="0" cellpadding="0">
																																<?php 
																																	if($countClicksPurchase>0)
																																	{
																																?>
																																<tr>
																																  <td width="51" align="left" valign="top" class="sitename" style="border-right:#cccccc 1px solid;">&nbsp;</td>
																																  <td width="129" align="left" valign="middle" class="sitename" style="border-right:#cccccc 1px solid;"><?php echo CLICKSTOPURCHASE;?></td>
																																  <td width="83" align="left" valign="middle" class="sitename" style="border-right:#cccccc 1px solid;"><?php echo CPC;?></td>
																																  <td width="108" align="left" valign="middle" class="sitename" style="border-right:#cccccc 1px solid;"><?php echo PRICENETWORK;?></td>
																																</tr>
																																<TR>
																																	<TD colspan="4">
																																		<table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
																																			<?php
																																			$cnter=0;
																																			while($fetClicksPurchase = mysql_fetch_array($getClicksPurchase))
																																			{
																																				$totalCost = $fetClicksPurchase[noOfClicks]*$fetNetworkAds[networkMinPrice];
																																			?>
																																			<?php
																																			$cnter++;
																																			if($cnter%2==1)
																																			{
																																				$class = 'normal2';
																																				$class2 = 'white';				
																																			}
																																			else
																																			{
																																				$class = 'normal';
																																				$class2 = 'gray';
																																			}
																																			if($cnter==$countClicksPurchase)
																																			{
																																				$style = 'style="border-bottom:#cccccc 1px solid;"';
																																			}
																																			?>
																																			<TR class="<?php echo $class;?>">
																																				<TD style="border-right:#cccccc 1px solid;" class="<?php echo $class2;?>_sitename2"><input value="<?php echo $fetClicksPurchase[noOfClicks];?>" type="radio" name="radPurchase" onClick="showPriceVal(this.value,'<?php echo $fetNetworkAds[networkMinPrice];?>',<?php echo $fetNetworkAds[networkId];?>);"></TD>
																																				<TD style="border-right:#cccccc 1px solid;" <?php echo $style;?>   class="<?php echo $class2;?>_sitename2"><?php echo $fetClicksPurchase[noOfClicks];?></TD>
																																				<TD style="border-right:#cccccc 1px solid;" <?php echo $style;?>   class="<?php echo $class2;?>_sitename2"><?php echo $fetNetworkAds[networkMinPrice];?></TD>
																																				<TD <?php echo $style;?>   class="<?php echo $class2;?>_sitename2"><?php echo number_format($totalCost,0,2,'');?></TD>
																																			</tr>
																																			<?php }?>
																																			<input type="hidden" name="network_min_price" id="network_min_price" value="<?php echo $fetNetworkAds[networkMinPrice]; ?>">
																																		</table>
																																	</TD>
																																</TR>
																																<?php
																																}
																																?>
																															</table>
																														</td>
																													</tr>
																													
																													<tr>
																														<td height="21" align="left" valign="middle" class="boxtxt">Ad Type</td>
																													</tr>
																													<tr>
																														<td height="19" align="left" valign="top" class="text">&nbsp;<?php echo $fetNetworkAds[networkType];?></td>
																													</tr>
																													<tr>
																														<td height="20" align="left" valign="top" class="boxtxt"><strong>Description</strong></td>
																													</tr>
																													<tr>
																														<td align="left" valign="top">&nbsp;<?php echo $fetNetworkAds[description];?></td>
																													</tr>
																													<tr>
																														<td align="left" valign="top">
																															<table width="100%" border="0" cellspacing="0" cellpadding="0">
																																<tr>
																																	<td width="107" align="left" valign="top" class="boxtxt"><strong>Date to Start: </strong></td>
																																	<td width="77" align="left" valign="top"><input id="startDate<?php echo $fetNetworkAds[networkId];?>" name="start_date<?php echo $fetNetworkAds[networkId];?>" class="flat" style="width: 80px;" maxlength="24" value="<?php echo date('Y-m-d');?>" onClick="javascript: obj<?php echo $fetNetworkAds[networkId];?>.show(event);" type="text">
																																		<a class="dateformat"></a>
																																		<script language="javascript" type="text/javascript">
																																			var obj<?php echo $fetNetworkAds[networkId];?> = new Calendar("obj<?php echo $fetNetworkAds[networkId];?>", 1, document.getElementById("startDate<?php echo $fetNetworkAds[networkId];?>"), "2009-04-20", "2009-04-20", "");
																																		</script>
																																	</td>
																																	<td align="left" valign="top">&nbsp;</td>
																																</tr>
																															</table>
																														</td>
																													</tr>
																													<tr>
																														<td align="left" valign="top">&nbsp;</td>
																													 </tr>
																												</table>
																											</td>
																										</tr>
																									</table>
																								</td>
																							</tr>
																						</table>
																					</td>
																				</tr>
																			</table>
																		</td>
																	</tr>
																</table>
															</TD>
														</TR>
													</form>
													<?php 
													}
													?>
												</table>
										</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td>
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
										  <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
										  <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
										  <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</td>
					<td>&nbsp;</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<?php

}
?>
